<?php

namespace App;

use App\Http\Services\FileManager;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;

/**
 * App\Banner
 *
 * @property int $id
 * @property int $img_id banner图片ID
 * @property string|null $title 标题
 * @property string|null $link_url 链接
 * @property string $location 放置位置：index首页
 * @property int $sort 排序
 * @property int $status 状态，0:隐藏，1:显示
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Banner onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereImgId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereLinkUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereLocation($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Banner withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Banner withoutTrashed()
 * @mixin \Eloquent
 * @property int $merchant_id 商家id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Banner whereMerchantId($value)
 */
class Banner extends Model
{
    protected $table='banner';
    use SoftDeletes;

    public static function getIndexBanner($merchant_id){
        $data=self::whereMerchantId($merchant_id)
            ->whereStatus(1)
            ->whereLocation('index')
            ->orderBy('sort','asc')
            ->get();
        if (count($data) > 0){
            /** @var self $item */
            foreach ($data as $item){
                $item->img_url=FileManager::getImgUrl($item->img_id);
            }
        }
        return $data ?? [];
    }
}
